 /*import Home from "pages/Home"
 import Login from "pages/Login"
 import Register from "pages/Register"
 import Search from "pages/Search"
 import Detail from "pages/Detail"
 import AddCartSuccess from "pages/AddCartSuccess"
 import ShopCart from "pages/ShopCart"*/
 const Home = () => import(/* webpackChunkName: "Home" */"pages/Home")
 const Login = () => import(/* webpackChunkName: "Login" */"pages/Login")
 const Register = () =>  import(/* webpackChunkName: "Register" */"pages/Register")
 const Search = () =>  import(/* webpackChunkName: "Search" */"pages/Search")
 const Detail = () =>  import(/* webpackChunkName: "Detail" */"pages/Detail")
 const AddCartSuccess = () =>  import(/* webpackChunkName: "AddCartSuccess" */"pages/AddCartSuccess")
 const ShopCart = () =>  import(/* webpackChunkName: "ShopCart" */"pages/ShopCart")
 const Trade = () =>  import(/* webpackChunkName: "Trade" */"pages/Trade")
 const Pay = () =>  import(/* webpackChunkName: "Pay" */"pages/Pay")
 const PaySuccess = () =>  import(/* webpackChunkName: "PaySuccess" */"pages/PaySuccess")
 const Center = () =>  import(/* webpackChunkName: "Center" */"pages/Center")
 const Order = () =>  import(/* webpackChunkName: "Center" */"pages/Center/Order")
 const TGOrder = () =>  import(/* webpackChunkName: "Center" */"pages/Center/TGOrder")

 import store from "store";
export default [
    {path:"/Home",component:Home},
    {name:"Search",
        path:"/Search/:keyword?",
        component:Search,
        props:route=>({
            keyword:route.params.keyword,
            categoryName:route.query.categoryName,
            category1Id:route.query.category1Id,
            category2Id:route.query.category2Id,
            category3Id:route.query.category3Id,
        })
    },
    {
        path:"/Login",
        component:Login,
        meta:{hideFooter:true},
        beforeEnter:(to, from, next)=>{
            // 1.当处于登录状态时 再也不能去登录页
            const userInfo = store.state.user.userInfo;
            if(userInfo.name){
                //说明 处于登录状态; 再也不能去登录页
                next("/")
            }else{
                //说明 处于未登录状态;  可以去登录页
                next()
            }
        }
    },
    {path:"/Register",component:Register,meta:{hideFooter:true}},
    {path:"/Detail/:skuid",component:Detail,props:true},
    {
        path:"/AddCartSuccess",
        component:AddCartSuccess,
        props: route => ({
            skuNum:route.query.skuNum
        }),
        beforeEnter:(to, from, next)=>{
            /*如果url中没有skuNum=1这个query 或者 sessionStorage中没有sph_skuInfo这个数据
            我们都不能直接跳转到AddCartSuccess页面 应该跳回到主页*/
            let skuInfo = window.sessionStorage.getItem("sph_skuInfo")
            let skuNum = to.query.skuNum;
            if(skuInfo && skuNum){
                //skuInfo和skuNum都存在 放行
                next()
            }else{
                next("/")
            }
        }
    },
    {path:"/ShopCart",component:ShopCart},
    {
        path:"/Trade",
        component:Trade,
        name:"Trade",
        // 3. 一定要确保     购物车组件->结算页面->支付页面->支付成功页面 这个顺序
        beforeEnter:(to, from, next)=>{
            if(from.path !== "/ShopCart"){
                next("/ShopCart")
            }else{
                next()
            }
        }
    },
    {
        path:"/Pay",
        component:Pay,
        name:"Pay",
        beforeEnter:(to, from, next)=>{
            if(from.path !== "/Trade"){
                next("/ShopCart")
            }else{
                next()
            }
        }
    },
    {
        path:"/PaySuccess",
        component:PaySuccess,
        name:"PaySuccess",
        beforeEnter:(to, from, next)=>{
            if(from.path !== "/Pay"){
                next("/ShopCart")
            }else{
                next()
            }
        }
    },
    {
        path:"/Center",
        component:Center,
        name:"Center",
        children:[
            {path:"Order",component:Order},
            {path:"TGOrder",component:TGOrder},
            {path:"",redirect:"Order"}
        ]
    },
    {path:"/",redirect:"/Home"}
 ]
